package com.zpark.resume.controller;

import com.zpark.resume.common.ResponseResult;
import com.zpark.resume.common.StatusCode;
import com.zpark.resume.entity.Education;
import com.zpark.resume.entity.Project;
import com.zpark.resume.entity.Training;
import com.zpark.resume.service.ITrainingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @PackageName: com.zpark.resume.controller
 * @ClassName: TrainingController
 * @Description:
 * @author: RZS
 * @date: 2023/6/1  22:13
 */
@RestController
@RequestMapping("/training")
@CrossOrigin
public class TrainingController {

    @Autowired
    private ITrainingService trainingService;

    /**
     * 根据cv_id查询Training数据
     * @param id cv_id
     * @return
     */
    @PostMapping("/find_by_cv_id/{id}")
    public ResponseResult<List<Training>> findRecommendByCvId(@PathVariable("id") Integer id){
        // 调用业务层接口查询数据
        List<Training> trainings = trainingService.findByCvId(id);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), trainings);
    }

    /**
     * 添加培训经历
     * @param training
     * @return
     */
    @PostMapping("/add")
    public ResponseResult<Void> addTra(@RequestBody Training training){
        // 调用业务层接口
        trainingService.addTraining(training);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
    }

    /**
     * 修改培训经历
     * @param training
     * @return
     */
    @PostMapping("/update")
    public ResponseResult<Void> changeTra(@RequestBody Training training){
        // 调用业务层接口
        trainingService.changeTrainingById(training);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
    }

    /**
     * 删除培训经历
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public ResponseResult<Void> removeTra(@PathVariable("id") Integer id){
        // 调用业务层接口
        trainingService.removeTrainingById(id);
        return new ResponseResult<>(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), null);
    }
}
